
package cn.hz.horse.ext;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

 
import cn.hz.horse.EzBooter;
import cn.hz.horse.EzHandle;
import cn.hz.horse.EzViewer;
import cn.hz.horse.EzViewerFunSimple;
import cn.hz.horse.EzViewerPanel;

public class MyTest2   {
 
	
	 public static void main(String[] args){
		 MyBatchHandle my=new MyBatchHandle();
		 MyBatchResHandle myRes=new MyBatchResHandle();
		 
		 EzBooter booter=new EzBooter();
		 booter.ready(my,myRes);
		 int start=0;
		 int size =5000;
		 EzViewer  vw=new EzViewer();
		 vw.appendFun(new EzViewerFunSimple());
		 new Thread(){
			 public void run(){
				 while(true){
					 try{
						 List<EzViewerPanel> ps=vw.view(); 
						 System.out.println("pp:      "+ps.size());
						 sleep(30000l);
					 }catch(Exception e){
						 
					 }
				 }
				
			 }
		 }.start();
		 while(true){
			 
			 booter.getWatcher().vaitNo();
			 List<Map<String,Object>>  list=MySQLClient.selBook(start, size);
			 List<BatCnter> bts= chgBooks (list);
			 System.out.println("list-size:   "+list.size());
			 if(list.size()<=0){
				 break;
			 }
			 start=start+size;
			 for(int i=0;i<bts.size();i++){
				 	BatCnter bt = bts.get(i);
					//map.put("id", "value "+i);
				 	booter.put(bt);
		     }
		 }
		 
	 }
	 
	 
	 
	 public static List<BatCnter>  chgBooks(List<Map<String,Object>> ks){
		 List<BatCnter> liss=new ArrayList<BatCnter>();
		 int size=100;
		 for(int i=0;i<ks.size();i++){
			 List<Map<String,Object>> kbs=new ArrayList<Map<String,Object>>();
			 boolean cnn=true;
			 for(int  ii=size*i;ii<size*(i+1);ii++){
				 if(ii<ks.size()){
					 kbs.add(ks.get(ii));
				 }else{
					 cnn=false;
					 break;
				 }
			 }
			 if(kbs.size()==0){
				 break;
			 }
			 BatCnter bt=new BatCnter();
			 bt.setEs(kbs);
			 liss.add(bt);
			 if(cnn==false){
				 break;
			 }
		 }
		 return liss;
	 }
}
